//
//  OrderPageViewController.m
//  much
//
//  Created by Believer Just on 2019/1/11.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "OrderPageViewController.h"
#import "OrderListViewController.h"
#import "SearchHistoryViewController.h"

@interface OrderPageViewController () <PublicPageViewControllerDataSource>

@property (strong, nonatomic) PublicTabButtonPageViewController *publicTabButtonPageViewController;
@property (strong, nonatomic) NSMutableArray *menuDataSourceArray;
@property (strong, nonatomic) NSMutableArray *controllerArray;

@end

@implementation OrderPageViewController

- (void)_reLayout {
    self.title = @"我的订单";
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.publicTabButtonPageViewController moveToControllerAtIndex:self.moveIndex animated:YES];
    });
    
    __weakConfigure
    [self.navigationView addNavigationRightView:CGRectMake(0, 0, 55, 40)
                                      titleFont:ICONFONT(14)
                                     titleColor:Color34
                                      titleText:@"\uE6a4"
                                        tapBack:^(UIView *v) {
                                            [__weakSelf searchAction];
                                        }];
}
- (void)searchAction {
    SearchHistoryViewController *vc = [[SearchHistoryViewController alloc] init];
    vc.searchHistoryType = fromOrderType;
    [self.navigationController pushViewController:vc animated:NO];
}


#pragma mark - PublicPageViewControllerDataSource
- (NSInteger)numberOfControllersInPagerController {
    return self.menuDataSourceArray.count;
}
- (NSString *)pagerController:(PublicPageViewController *)pagerController
                titleForIndex:(NSInteger)index {
    OrderMenuModel * model = self.menuDataSourceArray[index];
    return model.title;
}
- (UIViewController *)pagerController:(PublicPageViewController *)pagerController
                   controllerForIndex:(NSInteger)index {
    OrderListViewController * vc = [self.controllerArray objectAtIndex:index];
    OrderMenuModel * model = [self.menuDataSourceArray objectAtIndex:index];
    vc.index = model.tag;
    
    return vc;
}
- (void)pagerController:(PublicPageViewController *)pagerController transitionFromIndex:(NSInteger)formIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated {
    OrderMenuModel * model = [self.menuDataSourceArray objectAtIndex:toIndex];
    OrderListViewController * vc = [self.controllerArray objectAtIndex:toIndex];
    vc.index = model.tag;
}


#pragma mark - 懒加载
- (NSMutableArray *)menuDataSourceArray {
    if (!_menuDataSourceArray) {
        _menuDataSourceArray = [[NSMutableArray alloc] init];
        // 0:全部订单，1:待付款，2:待发货，3:待收货，4:已完成
        NSArray *arr;
        /**
        if (USER.isBuyer) {
            arr = @[@"全部", @"待付款", @"待发货", @"待收货", @"已完成", @"我的集采"];
        } else {
            arr = @[@"全部", @"待付款", @"待发货", @"待收货", @"已完成"];
        }
         */
        arr = @[@"全部", @"待付款", @"待发货", @"待收货", @"已完成"];
        for (int i = 0; i < arr.count; i++) {
            OrderMenuModel * model = [[OrderMenuModel alloc] init];
            model.title = arr[i];
            model.tag = i;
            [_menuDataSourceArray addObject:model];
        }
    }
    return _menuDataSourceArray;
}
- (NSMutableArray *)controllerArray {
    if (!_controllerArray) {
        _controllerArray = [[NSMutableArray alloc] init];
        for (int i = 0; i < self.menuDataSourceArray.count; i++) {
            OrderListViewController * vc = [[OrderListViewController alloc] init];
            [_controllerArray addObject:vc];
        }
    }
    return _controllerArray;
}
/** 页面控制器 */
- (PublicTabButtonPageViewController *)publicTabButtonPageViewController {
    if (!_publicTabButtonPageViewController) {
        _publicTabButtonPageViewController = [[PublicTabButtonPageViewController alloc] init];
        _publicTabButtonPageViewController.dataSource = self;
        
        _publicTabButtonPageViewController.contentTopEdging = 33;
        _publicTabButtonPageViewController.pagerBarViewRightSpacing = 16;
        _publicTabButtonPageViewController.progressWidth = 20;
        _publicTabButtonPageViewController.progressHeight = 2;
        _publicTabButtonPageViewController.cellEdging = 16;
        _publicTabButtonPageViewController.normalTextFont = APPFONT(14);
        _publicTabButtonPageViewController.selectedTextFont = APPFONT(14);
        
        _publicTabButtonPageViewController.barStyle = PublicPageBarStyleProgressBounceView;
        [self.view addSubview:self.publicTabButtonPageViewController.view];
        [_publicTabButtonPageViewController.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.and.bottom.equalTo(self.view);
            make.top.equalTo(self.navigationView.mas_bottom);
        }];
    }
    return _publicTabButtonPageViewController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

@implementation OrderMenuModel

@end
